﻿@model SCMS.UI.Models.ViewR4Payment
@{
    ViewBag.Title = "ViewR4PDetails";
}

<div class="partialViewCard">
    <div class="partialViewCardHeader">
        <h3>
            RFP: @Model.EntityPaymentRqst.RefNumber</h3>
    </div>
    @if (Model.CanApprove)
    {
        string linkText = null;
        string actionName = null;
        if (Model.EntityPaymentRqst.IsReviewed == true && Model.EntityPaymentRqst.IsAuthorized != true && !Model.EntityPaymentRqst.IsRejected)
        {
            linkText = "Authorize RFP";
            actionName = "LoadRFPForAuth";
        }
        else if (Model.EntityPaymentRqst.IsSubmitted && Model.EntityPaymentRqst.IsReviewed != true && !Model.EntityPaymentRqst.IsRejected)
        {
            linkText = "Review RFP";
            actionName = "ReviewRFP";
        }
        if (linkText != null)
        {
            <center>
                @Ajax.ActionLink(linkText, actionName, "RequestReview", new { id = "" }, new AjaxOptions
           {
               OnBegin = "ShowDialogueOR('" + linkText + ": " + Model.EntityPaymentRqst.RefNumber + "')",
               UpdateTargetId = "popup-page",
               LoadingElementId = "popup-loading",
               Url = Url.Action(actionName + "/" + Model.EntityPaymentRqst.Id, "RequestReview"),
               OnSuccess = "CenterPopupRFP"
           }) 
            </center>
        }
    }
    else
    {
        <br />
    }
    <fieldset style="text-align: left;">        
        <table width="98%" align="center" cellspacing="0" cellpadding="0" border="1" style="border: 1px solid grey;
            border-collapse: collapse; padding: 5px; font-size: 12px;">
            <tr class="gridheader">
                <th align="center" width="33.3%">
                    PO Ref No.
                </th>
                <th align="center" width="33.3%">
                    Date
                </th>
                <th align="center" width="33.3%">
                    Currency
                </th>
            </tr>
            <tr>
                <td align="center">
                    @Model.EntityPaymentRqst.PurchaseOrder.RefNumber
                </td>
                <td align="center">
                    @Model.EntityPaymentRqst.PreparedOn.ToShortDateString()
                </td>
                <td align="center">
                    @Model.EntityPaymentRqst.Currency.ShortName
                </td>
            </tr>
            <tr class="gridheader">
                <th align="center">
                    Payment Terms
                </th>
                <th align="center">
                    Payment Type
                </th>
                <th align="center">
                    Total Payment
                </th>
            </tr>
            <tr>
                <td align="center">@Model.EntityPaymentRqst.PaymentTerm.Code
                </td>
                <td align="center">
                    @Model.EntityPaymentRqst.PaymentType.Description
                </td>
                <td align="center">
                    <b>@Model.EntityPaymentRqst.TotalAmount.ToString("##,##0.00")</b>
                </td>
            </tr>
        </table>
        <br />
        <table width="98%" align="center" cellspacing="0" cellpadding="0" border="1" style="border: 1px solid grey;
            border-collapse: collapse; padding: 5px; font-size: 12px;">
            <tr>
                <td class="gridheader" style="width: 20%;">
                    Subject/Purpose:
                </td>
                <td style="width: 80%;">
                    @Model.EntityPaymentRqst.Subject
                </td>
            </tr>
            <tr>
                <td class="gridheader" style="width: 20%;">
                    Payment to:
                </td>
                <td>
                    @Model.EntityPaymentRqst.Supplier.Name
                </td>
            </tr>
        </table>
        <br />
        <table width="98%" align="center" cellspacing="0" cellpadding="0" border="1" style="border: 1px solid grey;
            border-collapse: collapse; padding: 5px; font-size: 12px;">
            <tr>
                <td class="gridheader" style="width: 20%;">
                    Request for:
                </td>
                <td>
                    <table>
                        <tr>
                            <td style="width: 20%;">
                                <div>
                                    @Html.RadioButtonFor(x => x.EntityPaymentRqst.RequestFor, "FullPayment", new { @disabled = "disabled" })
                                    Full Payment</div>
                            </td>
                            <td style="width: 20%;">
                                <div>
                                    @Html.RadioButtonFor(x => x.EntityPaymentRqst.RequestFor, "Rate_Instalment", new { @disabled = "disabled" })
                                    Rate/Instalment</div>
                            </td>
                            <td style="width: 20%;">
                                <div>
                                    @Html.RadioButtonFor(x => x.EntityPaymentRqst.RequestFor, "Adv_Payment_percentage", new { @disabled = "disabled" })
                                    Adv. Payment</div>
                            </td>
                            <td style="width: 20%;">
                                <div>
                                    @Html.RadioButtonFor(x => x.EntityPaymentRqst.RequestFor, "Adv_Final_Payment_percentage", new { @disabled = "disabled" })
                                    Adv. Final Payment</div>
                            </td>
                        </tr>
                    </table>
                </td>
            </tr>
        </table>
        <br />
        <table width="98%" align="center" cellspacing="0" cellpadding="0" border="1" style="border: 1px solid grey;
            border-collapse: collapse; padding: 5px; font-size: 12px;">
            <tr class="gridheader">
                <td align="left" colspan="5">
                    Payment Details:
                </td>
            </tr>
            <tr>
                <th align="center">
                    No.
                </th>
                <th align="center">
                    Project No
                </th>
                <th align="center">
                    Budget Line
                </th>
                <th align="center">
                    Amount
                </th>
                <th align="center">
                    Currency
                </th>
            </tr>
            @if (Model.paymentDetais.Count() > 0)
            {
                int count = 1;
                foreach (var item in Model.paymentDetais)
                {
                <tr>
                    <td style="width: 10%; text-align: center;">
                        @count
                    </td>
                    <td style="width: 10%; text-align: center;">
                        @item.projectNo
                    </td>
                    <td style="width: 40%;">
                        &nbsp; @item.BudgetLine @Html.Raw("&nbsp;") @item.BudgetLineDescription
                    </td>
                    <td style="width: 20%; text-align: right;">
                        @item.Amount.ToString("##,##0.00")
                        &nbsp;
                    </td>
                    <td style="width: 15%; text-align: center;">
                        @Model.EntityPaymentRqst.Currency.ShortName
                    </td>
                </tr>
                    count = count + 1;
                }
            }
        </table>
        @if (Model.CanPostFunds)
        { 
            <table width="98%" align="center" cellpadding="0" cellspacing="0">
                <tr>
                    <td align="right" width="100%" style="padding: 3px 0px 0px 0px">
                        <input type="button" id="btnPost" name="btnPost" value="Post Funds" class="btn tertiary"  onclick="ShowDialogue('Post Funds'); sendRequest('/FundPosting/PostRFP/@Model.EntityPaymentRqst.Id', 'popup-page', 'popup-loading'); CenterPopup();" />
                    </td>
                </tr>
            </table>
        }
        else
        {
            <br />
        }
        <table width="98%" align="center" cellspacing="0" cellpadding="0" border="1" style="border: 1px solid grey;
            border-collapse: collapse; padding: 5px; font-size: 12px;">
            <tr class="gridheader">
                <td align="left">
                    Supporting Documents in tender/payment dossier:
                </td>
            </tr>
            <tr>
                <td>
                </td>
            </tr>
        </table>
        <br />
        <table width="98%" align="center" cellspacing="0" cellpadding="0" border="1" style="border: 1px solid grey;
            border-collapse: collapse; padding: 5px; font-size: 12px;">
            <tr class="gridheader">
                <td align="left">
                    Remarks:
                </td>
            </tr>
            <tr>
                <td>
                    @Model.EntityPaymentRqst.Remarks
                </td>
            </tr>
        </table>
        <br />
        <table width="98%" align="center" cellspacing="0" cellpadding="0" border="1" style="border: 1px solid grey;
            border-collapse: collapse; padding: 5px; font-size: 12px;">
            <tr>
                <td align="right" class="gridheader" style="width: 30%;">
                    Master Budget Currency
                </td>
                <td style="width: 15%; text-align: center;">
                    <b>
                        @if (Model.EntityPaymentRqst.MBCurrencyId != null)
                        {
                            @Model.EntityPaymentRqst.Currency1.ShortName
                        }
                    </b>
                </td>
                <td class="gridheader" style="width: 15%;">
                    Total
                </td>
                <td style="width: 15%; text-align: center;">
                    <b>@ViewBag.MBValue</b>
                </td>
                <td class="gridheader" style="width: 25%;">
                    Request For Payment Value
                </td>
            </tr>
        </table>
        <br />
        <table width="98%" align="center" cellspacing="0" cellpadding="0" border="1" style="border: 1px solid grey;
            border-collapse: collapse; padding: 5px; font-size: 12px;">
            <tr class="gridheader">
                <td width="13%">
                    Authorization
                </td>
                <td width="29%">
                    RFP Prepared by
                </td>
                <td width="29%">
                    Finance Review/Approval of BL/PN
                </td>
                <td width="29%">
                    RFP Authorized by Manager/CD
                </td>
            </tr>
            <tr>
                <td class="gridheader">
                    Name:
                </td>
                <td>
                    @Model.EntityPaymentRqst.Staff1.Person.FirstName &nbsp; @Model.EntityPaymentRqst.Staff1.Person.OtherNames
                </td>
                <td>
                    @ViewBag.Reviewer
                </td>
                <td>
                    @ViewBag.Authorizer
                </td>
            </tr>
            <tr>
                <td class="gridheader">
                    Title:
                </td>
                <td>
                    @Model.EntityPaymentRqst.Staff1.Designation.Name
                </td>
                <td>
                    @ViewBag.ReviewerTitle
                </td>
                <td>
                    @ViewBag.AuthorizerTitle
                </td>
            </tr>
            <tr>
                <td class="gridheader">
                    Date:
                </td>
                <td>
                    @Model.EntityPaymentRqst.PreparedOn.ToString("dd/MM/yyyy h:mm tt")
                </td>
                <td>
                @if (ViewBag.ReviewedOn != null)
                {
                    @ViewBag.ReviewedOn.ToString("dd/MM/yyyy h:mm tt")
                }
                </td>
                <td>
                @if (ViewBag.AuthorizedOn != null)
                {
                    @ViewBag.AuthorizedOn.ToString("dd/MM/yyyy h:mm tt")
                }
                </td>
            </tr>
            <tr>
                <td class="gridheader">
                    Signature:
                </td>
                <td>
                    @if (Model.EntityPaymentRqst.Staff1.Person.SignatureImage != null)
                    { 
                        <img src="@Url.Action("Photo", "Person", new { id = Model.EntityPaymentRqst.Staff1.Person.Id, area = "" })" alt="" style="max-width: 150px;" />
                    }
                </td>
                <td>
                    @Html.Raw(ViewBag.ReviewerSignature)
                </td>
                <td>
                    @Html.Raw(ViewBag.AuthorizerSignature)
                </td>
            </tr>
        </table>
        <hr />
        @if (Model.EntityPaymentRqst.IsAuthorized == true)
        {
            <a class="btn btn-primary"  href="@Url.Action("Pdf", "Request4Payment", new { area = "Reports", RFPid = Model.EntityPaymentRqst.Id })" target="_blank" style="margin-left: 48%; margin-bottom: 2%;">
                Get PDF of RFP</a>
        }
    <br />
    </fieldset>
    <br />
</div>
<br />
<p>
    @Ajax.ActionLink("Back To List", "Index", new { id = "ViewR4P" }, new AjaxOptions
    {
        UpdateTargetId = "R4PDiv",
        LoadingElementId = "loading",
        Url = Url.Action("ViewR4P"),
        OnSuccess = "if (document.getElementById('table') != null) {initSorter();sorter.size(50);}"
    })
</p>
